#pragma once
#include<iostream>
#include<unistd.h>
#include<cstring>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
using namespace std;

#define PATH "./fifo.txt"
#define MODE 0666
class FIFO//管理fifo的创建与销毁
{
public:
    FIFO(string path)
    :_path(path)
    {
        int n=mkfifo(_path.c_str(),MODE);//创建，成功返回0
        if(n==0)
        {
            cout<<"name_pipe creat success..."<<endl;
        }
        else
        {
            cerr<<"name_pipe creat fail... errno: "<<errno<<",errstring: "<<strerror(errno)<<endl;
        }
    }
    ~FIFO()
    {
        int n=unlink(_path.c_str());//销毁，成功返回0
         if(n==0)
        {
            cout<<"name_pipe unlink success..."<<endl;
        }
        else
        {
            cerr<<"name_pipe unlink fail... errno: "<<errno<<",errstring: "<<strerror(errno)<<endl;
            //标准错误输出
        }
    }
private:
    string _path;
};

